package com.prs.crm.service.impl;

import java.util.Collection;

import org.hibernate.criterion.DetachedCriteria;
import org.springframework.beans.factory.annotation.Autowired;

import com.prs.crm.report.ExportConfig;
import com.prs.crm.report.ReportManager;
import com.prs.crm.report.ReportTable;
import com.prs.crm.service.QueryService;
import com.prs.crm.service.ReportService;

public class ReportServiceImpl implements ReportService{

	@Autowired
	private ReportManager reportManager;
	
	@Autowired
	private QueryService queryService;

	public void setReportManager(ReportManager reportManager) {
		this.reportManager = reportManager;
	}

	public ReportManager getReportManager() {
		return reportManager;
	}
	
	public void setQueryService(QueryService queryService) {
		this.queryService = queryService;
	}

	public QueryService getQueryService() {
		return queryService;
	}

	public String report(DetachedCriteria criteria,ReportTable table,ExportConfig config,int type)
	{
		table.setDataSource(this.getQueryService().query(criteria));
		return this.getReportManager().export(table, config, type);
	}
	/**
	 * 销售订单
	 */
	public String reportSaleOrder(DetachedCriteria criteria,ReportTable table,ExportConfig config,int type)
	{
		table.setDataSource(this.getQueryService().query(criteria));
		return this.getReportManager().exportSaleOrder(table, config, type);
	}
	
	public String reportPDF(DetachedCriteria criteria,ReportTable table,ExportConfig config)
	{
		table.setDataSource(this.getQueryService().query(criteria));
		return this.getReportManager().export(table, config, ReportManager.REPORTTYPE_PDF);
	}
	
	public String reportExcel(DetachedCriteria criteria,ReportTable table,ExportConfig config)
	{
		table.setDataSource(this.getQueryService().query(criteria));
		return this.getReportManager().export(table, config, ReportManager.REPORTTYPE_EXCEL);
	}
	
	
	public String report(ReportTable table,ExportConfig config,int type)
	{
		return this.getReportManager().export(table, config, type);
	}
	
	
	
	public String reportExcel(ReportTable table,ExportConfig config)
	{
		return this.getReportManager().export(table, config, ReportManager.REPORTTYPE_EXCEL);
	}
	

	public String reportPDF(ReportTable table,ExportConfig config)
	{
		return this.getReportManager().export(table, config, ReportManager.REPORTTYPE_PDF);
	}

	public String report(Collection<?> dataList, ReportTable table, ExportConfig config, int type) {
		table.setDataSource(dataList);
		return this.getReportManager().export(table, config, type);
	}

	
	
	/**
	 * 配送单
	 */
	public String exportAlreadyDistribution(DetachedCriteria criteria,
			ReportTable table, ExportConfig config, int type) {
		
		table.setDataSource(this.getQueryService().query(criteria));
		return this.getReportManager().exportAlreadyDistribution(table, config, type);
	}

	public String exportAssetsLiuXiang(DetachedCriteria criteria,
			ReportTable tables, ExportConfig config, int type) {
		tables.setDataSource(this.getQueryService().query(criteria));
		return this.getReportManager().exportAlreadyDistribution(tables, config, type);
	}
}
